﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;

namespace WuxiWTO.Web
{
    public partial class modifyPassword : System.Web.UI.Page
    {
        WTODataContext contex = new WTODataContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_name"] == null && Request.Cookies["wtouser"] == null)
            {
                Response.Redirect(Server.HtmlEncode("login.aspx?ret=userCenter.aspx"));
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            supporter user = contex.supporters.SingleOrDefault(p => p.supporter_login_name == Session["user_name"].ToString());
            if (user != null)
            {
                if (this.txtOldPass.Text.Trim() != user.supporter_password)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "paramerr", "alert('旧密码不正确');", true);
                    return;
                }
                user.supporter_password = this.txtNewPass.Text.Trim();
                contex.SubmitChanges();
                ClientScript.RegisterStartupScript(this.GetType(), "paramerr2", "alert('密码修改成功,将在下次登录启用');", true);
                this.txtOldPass.Text = "";
                this.txtNewPass.Text = "";
                this.txtNewPass2.Text = "";
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "paramerr3", "alert('数据查询出现异常');", true);
                return;
            }
        }
    }
}